package com.hencoder.hencoderpracticedraw1.practice;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

public class Practice2DrawCircleView extends View {

    public Practice2DrawCircleView(Context context) {
        super(context);
    }

    public Practice2DrawCircleView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Practice2DrawCircleView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

//        练习内容：使用 canvas.drawCircle() 方法画圆
//        一共四个圆：1.实心圆 2.空心圆 3.蓝色实心圆 4.线宽为 20 的空心圆

        // 1. 实心圆
        drawSlidCircle(canvas);

        // 2. 空心圆
        drawHollowCircle(canvas);

        // 3. 蓝色实心圆
        drawSlidBlueCircle(canvas);

        /**
         * 4. 线宽 20 的空心圆
         */
        draw20WithCirlr(canvas);
    }

    /**
     * 画实心圆
     *
     * @param canvas
     */
    private void drawSlidCircle(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColor(Color.BLACK);
        paint.setAntiAlias(true);

        canvas.drawCircle(300, 200, 150, paint);
    }

    /**
     * 空心圆
     *
     * @param canvas
     */
    private void drawHollowCircle(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColor(Color.BLACK);
        paint.setAntiAlias(true);
        paint.setStrokeWidth(3);
        paint.setStyle(Paint.Style.STROKE);

        canvas.drawCircle(800, 200, 150, paint);
    }

    /**
     * 画一个蓝色实心圆
     *
     * @param canvas
     */
    private void drawSlidBlueCircle(Canvas canvas) {
        Paint paint = new Paint();
        paint.setColor(Color.BLUE);
        // 抗锯齿
        paint.setAntiAlias(true);

        canvas.drawCircle(300, 600, 150, paint);
    }

    /**
     * 线宽20的空心圆
     */
    private void draw20WithCirlr(Canvas canvas) {
        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setColor(Color.BLACK);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeWidth(40);

        canvas.drawCircle(800, 600, 150, paint);
    }

}
